# ls = ["apple", "banana", "orange"]\
#
# print (ls)
#
# print ("-----------------")
# result = ",".join(ls)
# print(result)

# Is = ["apple","banana","orange"]
# print (Is)
#
# result = ",".join(Is)
# print(result)

# try:
#     # 这里故意引发 TypeError，比如将字符串和数字相加
#     result = "abc" + 123
# except TypeError:
#     print("捕获到 TypeError 异常，类型不匹配的操作出错啦")
#


#常见函数的举例
#1.strip  默认去空格(首尾的空白字符（空格、换行 \n、制表符 \t 等 ），但中间的空白会保留。)
text = "     hello   ,  python     "
result = text.strip()
print(f"{result}")#hello   ,  python

#2.split  分割
text = "hello,python,world"
result = text.split(",")
print(f"{result}")#['hello', 'python', 'world']

#3.join  连接
text = [" I ","learn " ,"python "]
result = "".join(text)
print(f"{result}") #I learn python

#4.replace 替换
text = "python is hard "
result = text.replace("hard","easy")
print(f"{result}") #python is easy


print("----------------------------------------------")


val = pow(2, 1000)  # 计算 2 的 1000 次方（结果是整数）
digits = len(str(val))  # 先转为字符串，再用 len() 获取位数
print(f"2^1000 的位数是: {digits}")  # 输出 302
print("----------------------------------------------")

# a=10
# b = a**2
# print(f"{b}")
# print(b)


#Python 命名规则要求标识符不能以数字开头
# 5my =  123
# print(f"{5my}")
#报错
my2 = 123
print(f"{my2}")

print("----------------------------------------------")


a = 10
b = 20
c = 30
a,b,c = c,a,b
print(f"{a,b,c}")

print("----------------------------------------------")


d = {'a': 1, 'b': 2, 'c': 3}

# 获取字典的值视图
values_view = d.values()

# 打印视图对象及其类型
print(f"values_view: {values_view}")
print(f"type: {type(values_view)}")  # 输出 <class 'dict_values'>

# 验证是否为元组、列表、集合
print(f"是否为元组: {isinstance(values_view, tuple)}")  # False
print(f"是否为列表: {isinstance(values_view, list)}")  # False
print(f"是否为集合: {isinstance(values_view, set)}")  # False


print("----------------------------------------------")
# fruits = ['apple', 'banana', 'cherry', 'apple']
#
# # 查找 'apple' 的索引
# first_apple_index = fruits.index('apple')
# print(f"第一次出现 'apple' 的索引: {first_apple_index}")  # 输出 0
#
# # 查找 'cherry' 的索引
# cherry_index = fruits.index('cherry')
# print(f"第一次出现 'cherry' 的索引: {cherry_index}")  # 输出 2

# list = [1,2,3,5,76,8]
# result = list.index(76)
# print(f"{result}")


# 直接用 {} 生成的是字典类型（空字典 ）；() 生成元组，[] 生成列表
print("----------------------------------------------")

# class Student:
#     def __init__(self, sid, name):
#         self.sid = sid
#         self.name = name
#
#     def get_info(self):
#         return f"学号:{self.sid} 姓名:{self.name}"
#
# class Undergraduate(Student):
#     def __init__(self, sid, name, major):
#         super().__init__(sid, name)
#         self.major = major
#
# class Graduate(Student):
#     def __init__(self, sid, name, supervisor):
#         super().__init__(sid, name)
#         self.supervisor = supervisor
#
# # 测试用例
# students = [
#     Undergraduate("1001", "张三", "计算机"),
#     Graduate("2001", "李四", "王教授")
# ]
# for s in students:
#     print(s.get_info())

print("----------------------------------------------")

#
# class Student:
#     def __init__(self,sid,name):
#         self.sid = sid
#         self.name = name
#
#     def get_info(self):
#         return f"学号：{self.sid} 姓名：{self.name}"
#
# class Undergraduate(Student):
#     def __init__(self,sid,name,major):
#         super().__init__(sid,name)
#         self.major = major
#
# # 本科生子类，增加专业属性
# # class Undergraduate(Student):
# #     def __init__(self, sid, name, major):
# #         super().__init__(sid, name)
# #         self.major = major
#
#     # 重写 get_info，补充专业信息
#     # def get_info(self):
#     #

#     def get_info(self):
#         return super().get_info() + f" 专业：{self.major}"
# # 研究生子类，增加导师属性
# class Graduate(Student):
#     def __init__(self,sid,name,supervisor):
#         super().__init__(sid,name)
#         self.supervisor = supervisor
#
# # class Graduate(Student):
# #     def __init__(self, sid, name, supervisor):
# #         super().__init__(sid, name)
# #         self.supervisor = supervisor
#     def get_info(self):
#         return super().get_info() + f" 导师：{self.supervisor}"
#     # 重写 get_info，补充导师信息
#     # def get_info(self):
#     #     return super().get_info() + f" 导师:{self.supervisor}"
#
# # 测试用例
# students = [
#     Undergraduate("1001", "张三", "计算机"),
#     Graduate("2001", "李四", "王教授")
# ]
# for s in students:
#     print(s.get_info())

# class Student:
#     def __init__(self, sid, name):
#         self.sid = sid
#         self.name = name
#
#     def get_info(self):
#         return f"学号:{self.sid} 姓名:{self.name}"
#
# class Undergraduate(Student):
#     def __init__(self, sid, name, major):
#         super().__init__(sid, name)
#         self.major = major
#
#     def get_info(self):
#         return super().get_info()+f"专业：{self.major}"
#
#
# class Graduate(Student):
#     def __init__(self, sid, name, supervisor):
#         super().__init__(sid, name)
#         self.supervisor = supervisor
#
#     def get_info(self):
#         return super().get_info()+f"导师：{self.supervisor}"
#
# # 测试用例
# students = [
#     Undergraduate("1001", "张三", "计算机"),
#     Graduate("2001", "李四", "王教授")
# ]
# for s in students:
#     print(s.get_info())


class Student:
    def __init__(self, sid, name):
        self.sid = sid
        self.name = name

    def get_info(self):
        return f"学号:{self.sid} 姓名:{self.name}"

class Undergraduate(Student):
    def __init__(self, sid, name, major):
        super().__init__(sid, name)
        self.major = major

    def get_info(self):
        return super().get_info()+f"专业：{self.major}"


class Graduate(Student):
    def __init__(self, sid, name, supervisor):
        super().__init__(sid, name)
        self.supervisor = supervisor

    def get_info(self):
        return super().get_info()+f"导师：{self.supervisor}"

# 测试用例
students = [
    Undergraduate("1001", "张三", "计算机"),
    Graduate("2001", "李四", "王教授")
]
for s in students:
    print(s.get_info())